package com.b2c.services;

import java.util.List;

import org.hibernate.Session;

import com.b2c.dao.EticMarkaDAO;
import com.b2c.entity.EticMarka;
import com.b2c.utils.HibernateUtil;

public class EticMarkaController {
	public static void main(String[] args) {
		EticMarkaController controller = new EticMarkaController();
		controller.getMarka(1);
	}

	public EticMarka getMarka(long id) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		EticMarkaDAO markaDAO = new EticMarkaDAO(session);
		EticMarka eticMarka = markaDAO.getMarkaById(id);
		session.close();
		return eticMarka;
	}

	public void markaEkle(EticMarka eticMarka) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		EticMarkaDAO eticMarkaDAO = new EticMarkaDAO(session);
		eticMarkaDAO.markaEkle(eticMarka);
		session.getTransaction().commit();
		session.close();
	}

	public void markaGuncelle(EticMarka eticMarka) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		EticMarkaDAO eticMarkaDAO = new EticMarkaDAO(session);
		eticMarkaDAO.markaGuncelle(eticMarka);
		session.getTransaction().commit();
		session.close();
	}

	public void markaEkle(String markaAd) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		EticMarkaDAO eticMarkaDAO = new EticMarkaDAO(session);
		EticMarka eticMarka = new EticMarka();
		eticMarka.setAd(markaAd);
		eticMarkaDAO.markaEkle(eticMarka);
		session.getTransaction().commit();
		session.close();
	}

	public List<EticMarka> getTumMarkalar() {
		Session session = HibernateUtil.getSessionFactory().openSession();
		EticMarkaDAO markaDAO = new EticMarkaDAO(session);
		List<EticMarka> list = markaDAO.getTumMarkalar();
		session.close();
		return list;
	}

	public void markaSil(EticMarka eticMarka) {
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		EticMarkaDAO markaDAO = new EticMarkaDAO(session);
		markaDAO.markaSil(eticMarka);
		session.getTransaction().commit();
		session.close();
	}

}
